package com.tourism.controller;

import com.tourism.common.Result;
import com.tourism.entity.Menu;
import com.tourism.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/menu")
@CrossOrigin
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public Result getMenuList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String description) {
        return menuService.getMenuList(page, pageSize, name, description);
    }

    @GetMapping("/{id}")
    public Result getMenuById(@PathVariable Integer id) {
        return menuService.getMenuById(id);
    }

    @PostMapping("/add")
    public Result addMenu(@RequestBody Menu menu) {
        return menuService.addMenu(menu);
    }

    @PutMapping("/update")
    public Result updateMenu(@RequestBody Menu menu) {
        return menuService.updateMenu(menu);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteMenu(@PathVariable Integer id) {
        return menuService.deleteMenu(id);
    }

    @PostMapping("/batch") // 修改为 @PostMapping
    public Result batchDeleteMenus(@RequestBody List<Integer> ids) {
        return menuService.batchDeleteMenus(ids);
    }

    @GetMapping("/all")
    public Result getAllMenus() {
        return menuService.getAllMenus();
    }
}
